package meituan;

import java.util.Scanner;

/**
 * @Author Stringzhua
 * @Date 2024/11/9 15:04
 * description:
 */
public class test04 {
    //判断一个数是否为质数
    public static boolean isZhi(int num) {
        if (num < 2) {
            return false;
        }
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static long maxPoint(int[] a, int[] b) {
        long result = 0;
        Boolean[] usedA = new Boolean[a.length];
        Boolean[] usedB = new Boolean[b.length];
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < b.length; j++) {
                if (!usedA[i] && !usedB[j]) {
                    boolean isPrimeA = isZhi(a[i]);
                    boolean isPrimeB = isZhi(b[j]);
                    if (isPrimeA && isPrimeB) {
                        result += a[i] + b[j];
                        usedA[i] = true;
                        usedB[j] = true;
                    } else if (isPrimeA || isPrimeB) {
                        result += Math.max(a[i], b[j]);
                        usedA[i] = true;
                        usedB[j] = true;
                    } else {
                        result += a[i] + b[j];
                        usedA[i] = true;
                        usedB[j] = true;
                    }
                }
            }
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[m];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        long maxIncrease = maxPoint(a, b);
        System.out.println(maxIncrease);
    }
}
